package com.cjw.controller.userMange;

import com.cjw.config.annotation.OperationLogAnnotation;
import com.cjw.pojo.dto.database.PageDTO;
import com.cjw.pojo.dto.userMange.UserAuthorSimpleDTO;
import com.cjw.pojo.dto.userMange.UserSimpleDTO;
import com.cjw.pojo.query.systemManage.AddUserRole;
import com.cjw.pojo.query.systemManage.QueryAuthorDTO;
import com.cjw.pojo.query.userMange.UserQuery;
import com.cjw.service.userMange.UserAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author : cjw
 * @date: : 2022/2/7 14:30
 * @description : 用户管理资源 controller
 */
@RestController
@RequestMapping("/admin/userAccount")
@Api("用户管理资源")
public class UserAccountController {
    @Autowired
    private UserAccountService userAccountService;

    @PostMapping("/findAllUsers")
    @ApiOperation("查看全部用户")
    @OperationLogAnnotation(operModul = "用户管理-账号管理",operType = "查看全部用户",operDesc = "查询")
    public PageDTO<List<UserSimpleDTO>> findAllUsers(@RequestBody UserQuery userQuery) {
        return userAccountService.findAllUsers(userQuery);
    }

    @PostMapping("/changeUser/state")
    @ApiOperation("修改用户状态")
    @OperationLogAnnotation(operModul = "用户管理-账号管理",operType = "修改用户状态",operDesc = "修改")
    public Integer changeUserState(Long id) {
        return userAccountService.changeUserState(id);
    }

    @PostMapping("/author/findAllUsers")
    @ApiOperation("查询用户权限管理列表")
    @OperationLogAnnotation(operModul = "用户管理-用户权限管理",operType = "查询用户权限管理列表",operDesc = "查询")
    public PageDTO<List<UserAuthorSimpleDTO>> findAllUsersAuthor(@RequestBody @Valid QueryAuthorDTO queryAuthorDTO) {
        return userAccountService.findAllUsersAuthor(queryAuthorDTO);
    }

    @PostMapping("/author/ban")
    @ApiOperation("封禁用户权限")
    @OperationLogAnnotation(operModul = "用户管理-用户权限管理",operType = "封禁用户权限",operDesc = "添加")
    public Boolean ban(Long userId, Integer type) {
        return userAccountService.ban(userId, type);
    }

    @PostMapping("/author/unseal")
    @ApiOperation("解禁用户权限")
    @OperationLogAnnotation(operModul = "用户管理-用户权限管理",operType = "解禁用户权限",operDesc = "删除")
    public Boolean unseal(Long userId, Integer type) {
        return userAccountService.unseal(userId, type);
    }

    @PostMapping("/author/addrole")
    @ApiOperation("分配角色")
    @OperationLogAnnotation(operModul = "用户管理-用户权限管理",operType = "分配角色",operDesc = "修改")
    public Boolean addRole(@RequestBody @Valid AddUserRole addUserRole) {
        return userAccountService.addRole(addUserRole);
    }
}
